//
//  ViewController.m
//  AppManager
//
//  Created by allen on 16/3/26.
//  Copyright © 2016年 allen. All rights reserved.
//

#import "ViewController.h"
#import "AppInfoModel.h"
#import "AppInfoView.h"

@interface ViewController ()

@property (nonatomic, strong)NSArray * appList;

@end

@implementation ViewController

- (NSArray *)appList {
    if(!_appList){
        _appList = [AppInfoModel appInfoList];
    }
    return _appList;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    int cols = 3;
    CGFloat startH = 20;
    CGFloat viewW = 80;
    CGFloat viewH = 90;
    CGFloat marginX = (self.view.bounds.size.width - cols * viewW) / (cols + 1);
    CGFloat marginY = 10;
    NSUInteger count = self.appList.count;
    
    for(int i = 0; i < count; i++){
        
        int row = i / cols;
        int col = i % cols;
        CGFloat x = marginX + (viewW + marginX) * col;
        CGFloat y = startH + (viewH + marginY) * row;
        
        AppInfoView * appView = [AppInfoView appInfoViewWithAppInfo:self.appList[i]];
        
        appView.frame = CGRectMake(x, y, viewW, viewH);
        
        [self.view addSubview:appView];
        
    }
}


@end
